
'use strict';
var imageinfo = require('imageinfo'),
    fs = require('fs');

let path = '/Users/yybs/Develop/code/android/zhidet-company/app/src/main/res';





function walk(path, floor, handleFile) {  
    handleFile(path, floor);  
    floor++;  
    fs.readdir(path, function(err, files) {  
        if (err) {  
            console.log('read dir error');  
        } else {  
            files.forEach(function(item) {  
                var tmpPath = path + '/' + item;  
                fs.stat(tmpPath, function(err1, stats) {  
                    if (err1) {  
                        console.log('stat error');  
                    } else {  
                        if (stats.isDirectory()) {  
                            walk(tmpPath, floor, handleFile);  
                        } else {  
                            handleFile(tmpPath, floor);  
                        }  
                    }  
                })  
            });  
  
        }  
    });  
}  

function handleFile(path, floor) {  
    var blankStr = '';  
    for (var i = 0; i < floor; i++) {  
        blankStr += '    ';  
    }  
  
    fs.stat(path, function(err1, stats) {  
        if (err1) {  
            console.log('stat error');  
        } else {  
            if (stats.isDirectory()) {  
                console.log('+' + blankStr + path);  
            } else {  
                if (path.endsWith('.png')) {
                    fs.readFile(path, function(err, data) {
                        if (err) throw err;
                        var  info = imageinfo(data);
                        if (info.mimeType != 'image/png') {
                        console.log("Data is type:", info.mimeType);
                        console.log('path',path);
                        console.log("  Size:", data.length, "bytes");
                        console.log("  Dimensions:", info.width, "x", info.height);
                        }
                        
                    });
                }
            

                console.log('-' + blankStr + path);  
            }  
        }  
    }) 
}  


walk('/Users/yybs/Develop/code/android/zhidet-company/app/src/main/res', 0, handleFile);  